package thread;

import java.util.ArrayList;

public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        ArrayList<Integer> list = new ArrayList<>();
        Thread t = new Thread(){
            public void run(){
                for (int i = 0; i < 10000; i++) {
                    synchronized (list){
                        list.add(i);
                    }
                }
            }
        };

        Thread t2 = new Thread(){
            public void run(){
                for (int i = 0; i < 10000; i++) {
                    synchronized (list){
                        list.add(i);
                    }
                }
            }
        };

        t.start();
        t2.start();

        Thread.sleep(1000);

        System.out.println(list.size());
    }
}
